package cn.zmit.kuxi.adapter;

import java.util.List;

import cn.zmit.kuxi.R;
import cn.zmit.kuxi.adapter.LuckyNumberAdapter.ViewHolder;
import cn.zmit.kuxi.contants.Url;
import cn.zmit.kuxi.entity.ExpressEntity;
import cn.zmit.kuxi.entity.LuckNumEntity;
import cn.zmit.kuxi.image.ImageDisplayer;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ExpressAdapter extends BaseAdapter {

	public List<ExpressEntity> mCellDataList;
	public Context mContext;

	public ExpressAdapter(List<ExpressEntity> celldatalist, Context context) {
		this.mCellDataList = celldatalist;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		return mCellDataList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mCellDataList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		View view;
		ViewHolder holder;
		if (convertView != null) {
			view = convertView;
			holder = (ViewHolder) view.getTag();
		} else {
			view = View.inflate(mContext, R.layout.item_express, null);
			holder = new ViewHolder();
			holder.tv_phase = (TextView) view.findViewById(R.id.tv_phase);
			holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
			holder.tv_status = (TextView) view.findViewById(R.id.tv_status);
			holder.tv_time = (TextView) view.findViewById(R.id.tv_time);
			holder.iv_pic = (ImageView) view.findViewById(R.id.iv_pic);
			view.setTag(holder);
		}
		holder.tv_phase.setText("第" + mCellDataList.get(position).getPhase()
				+ "期");
		holder.tv_phase.setTextColor(Color.parseColor("#FF0000"));
		holder.tv_name.setText(mCellDataList.get(position).getName());
		ImageDisplayer.getInstance().dispalyImageWithRadius(
				Url.IMAGE_PICTURES + mCellDataList.get(position).getPic(), holder.iv_pic, 0);
		int status =Integer.parseInt(mCellDataList.get(position).getStatus()) ;
		if(status==0){
			holder.tv_status.setText("发货状态：未发货");
			holder.tv_time.setText("发货时间：未发货");
		}else if(status==1){
			holder.tv_status.setText("发货状态：已发货");
			holder.tv_time.setText("发货时间："+mCellDataList.get(position).getTime());
		}
		return view;
	}

	static class ViewHolder {
		TextView tv_phase;
		TextView tv_name;
		TextView tv_status;
		TextView tv_time;
		ImageView iv_pic;
	}

}
